package com.common.core;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.jfinal.upload.OreillyCos;
import com.mvc.controller.CDKeyController;
import com.mvc.controller.CarController;
import com.mvc.controller.MessageController;
import com.mvc.controller.NoticeController;
import com.mvc.controller.StoryController;
import com.mvc.controller.StyleController;
import com.mvc.controller.SystemController;
import com.mvc.controller.TributeController;
import com.mvc.controller.UserController;
import com.mvc.controller.VenueController;
import com.mvc.controller.WXGameController;
import com.mvc.controller.WorshipController;
import com.mvc.model.CDKey;
import com.mvc.model.Car;
import com.mvc.model.Dead;
import com.mvc.model.Deeds;
import com.mvc.model.Message;
import com.mvc.model.Notice;
import com.mvc.model.Style;
import com.mvc.model.Tribute;
import com.mvc.model.User;
import com.mvc.model.Venue;
import com.mvc.model.Version;
import com.mvc.model.Worship;
import com.mvc.service.impl.TimeTaskService;

public class AppConfig extends JFinalConfig {
	
	
	@Override
	public void afterJFinalStart() {
		super.afterJFinalStart();
		//上传文件重名策略的使用
		OreillyCos.setFileRenamePolicy(new UpFileRenamePolicy());
		//定时任务
		new TimeTaskService().start();
	}

	public void configConstant(Constants me) {
		PropKit.use("config.properties");
		me.setDevMode(true);
		//上传文件保存路径
//		me.setBaseUploadPath("upload");
		me.setBaseUploadPath(PropKit.get("UploadPath"));
		me.setBaseViewPath("/WEB-INF/view");
		me.setViewType(ViewType.JSP); 	
	}

	public void configRoute(Routes me) {
		me.add("/user",UserController.class);
		me.add("/venue",VenueController.class);
		me.add("/message",MessageController.class);
		me.add("/story",StoryController.class);
		me.add("/tribute",TributeController.class);
		me.add("/worship",WorshipController.class);
		me.add("/system",SystemController.class);
		me.add("/style",StyleController.class);
		me.add("/notice",NoticeController.class);
		me.add("/car",CarController.class);
		me.add("/cdkey",CDKeyController.class);
		me.add("/game",WXGameController.class);
	}

	public void configPlugin(Plugins me) {
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
		me.add(c3p0Plugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		arp.addMapping("user","id", User.class);	
		arp.addMapping("venue","id", Venue.class);	
		arp.addMapping("message","id", Message.class);	
		arp.addMapping("dead","id", Dead.class);	
		arp.addMapping("deeds","id", Deeds.class);	
		arp.addMapping("notice","id", Notice.class);	
		arp.addMapping("style","id", Style.class);	
		arp.addMapping("tribute","id", Tribute.class);	
		arp.addMapping("worship","id", Worship.class);	
		arp.addMapping("version","id", Version.class);	
		arp.addMapping("car","id", Car.class);	
		arp.addMapping("cdkey","id", CDKey.class);
	}

	public void configInterceptor(Interceptors me) {
	}

	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler());
	}
}
